package kadledav.adventure.framework.controll.commands.abstr;

import java.io.PrintStream;
import java.util.List;
import java.util.Scanner;

import kadledav.adventure.framework.model.world.Item;
import kadledav.adventure.framework.model.world.Player;

public abstract class MoveItemCommand extends ParameterActionCommand {

	public MoveItemCommand(PrintStream out, Scanner in, Player player) {
		super(out, in, player);
	}

	@Override
	public void execute(String[] userCommand) {
		Integer itemNumber = parseFirstNumber(userCommand, getCommadnPrefix());
		List<Item> items = getItemsSource();
		if (itemNumber == null || !checkIsInRange(items, itemNumber)) {
			wrongCommandArgument();
			return;
		}
		Item item = items.get(itemNumber);
		if (item == null) {
			wrongCommandArgument();
			return;
		}
		doTheCommand(item);
	}

	
	abstract protected List<Item> getItemsSource();

	abstract protected String getCommadnPrefix();

	abstract protected void doTheCommand(Item item);
}
